import { Dispatch } from "redux"
import {
    getPartitionsRequest,
    getRankingPartitionsRequest,
    getRankingRequest
} from '@/api/request'
import * as actionTypes from '../constants'

// 页面级别action
// promise.all
export const getHomeDataAction=(rId:string)=>{
    return (dispatch:Dispatch)=>{
        dispatch(setLoading(true))
        return Promise.all([
            getPartitionsRequest(),
            getRankingPartitionsRequest(),
            getRankingRequest(rId),
        ]).then(([partitionResult,rankingPartitionsResult,videoResult])=>{
            // console.log(partitionResult,'-----');
            let partitions = partitionResult.data[0];
            partitions.filter((partitions:any)=>[13,23,11
                ,177].indexOf(partitions.id)===-1)
            dispatch(setOneLevelPartitions(partitions))
            dispatch(setRankingPartitions(rankingPartitionsResult.data))
            dispatch(setRankingVideos(videoResult.data.list))
            dispatch(setLoading(false))
        })
    }
}

export const setOneLevelPartitions=(data:any[])=>({
    type:actionTypes.SET_ONE_LEVEL_PARTITONS,
    data
})

export const setLoading=(data:boolean)=>({
    type:actionTypes.SET_LOADING,
    data
})

export const setRankingPartitions=(data:any[])=>({
    type:actionTypes.SET_RANKING_PARTITIONS,
    data
})

export const setRankingVideos=(data:any[])=>({
    type:actionTypes.SET_RANKING_VIDEOS,
    data
})